package com.xwaf.platform.web.config.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.xwaf.platform.system.api.entity.auth.User;

public class ShiroRequestUtils {

	/**
	 * 
	 * <p>
	 * 获取当前登录的用户，若用户未登录，则返回未登录 json
	 * <p>
	 * 
	 * @author 李聪 <br>
	 * @email xwaf_love@yeah.net <br>
	 * @since JDK 1.8<br>
	 * @date 2019年12月30日 上午9:22:38 <br>
	 * @see 无<br>
	 * @return
	 * @demo <br>
	 */
	public static User currentLoginUser() {
		Subject subject = SecurityUtils.getSubject();
		if (subject.isAuthenticated()) {
			Object principal = subject.getPrincipals().getPrimaryPrincipal();
			if (principal instanceof User) {
				return (User) principal;
			}
		}
		return null;
	}
}
